package com.example.myapplication.login;


import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.mvp.mvp.view.BaseFragment;
import com.example.myapplication.R;
import com.example.myapplication.a_mvp.contract.MyContract;
import com.example.myapplication.a_mvp.presenter.LoginPresenter;
import com.example.myapplication.a_utils.Dag_Mod;
import com.example.myapplication.a_utils.DaggerDag_Com;
import com.example.myapplication.b_entity.Login_Entity;
import com.example.myapplication.b_entity.Daxia;
import com.example.myapplication.b_entity.Reg_Entity;

import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

/**
 * A simple {@link Fragment} subclass.
 */
public  class Login_Fragment extends BaseFragment<LoginPresenter> implements MyContract.MyView {


    private ImageView regImg;
    private TextView mainText;
    private EditText mainEdi;
    private Button mainButt;
    private TextView mainText2;

    @Override
    public int findlayout() {
        return R.layout.fragment_login_;
    }

    @Override
    public void initView() {

        regImg = (ImageView) findViewById(R.id.reg_img);
        mainText = (TextView) findViewById(R.id.main_text);
        mainEdi = (EditText) findViewById(R.id.main_edi);
        mainButt = (Button) findViewById(R.id.main_butt);
        mainText2 = (TextView) findViewById(R.id.main_text2);
    }
    //接口回调数据
    interface GetType{
        void Type(int  i);
    }
    private GetType getType;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getType = (GetType) getActivity();
    }
    @Override
    public void initData() {
        final Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                String trim = mainEdi.getText().toString().trim();
                if (trim.equals("")){
                    getActivity().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            mainButt.setBackground(getResources().getDrawable(R.drawable.mybutton));
                            mainButt.setEnabled(false);
                        }
                    });

                }else{
                    getActivity().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            mainButt.setBackground(getResources().getDrawable(R.drawable.mybutton));
                            mainButt.setEnabled(true);

                        }
                    });
                }
            }
        },0,20);
        DaggerDag_Com.builder().dag_Mod(new Dag_Mod(this)).build().login(this);
        mainButt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mypre.login("a","a");
            }
        });



        mainText2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getType.Type(1);
            }
        });
    }


    @Override
    public void show_reg(Reg_Entity reg_entity) {

    }

    @Override
    public void show_login(Login_Entity login_entity) {
        if (login_entity.getCode().equals("200")){
            getType.Type(3);
        }
    }

    @Override
    public void show_daxia(List<Daxia.DataBean> list) {

    }


}
